package com.quickask.action;

import com.opensymphony.xwork2.ActionSupport;
import com.quickask.entity.AsknowAnswerLocationSetEntity;
import com.quickask.entity.AsknowAnswerSet;
import com.quickask.entity.AsknowAnswerSetEntity;
import com.quickask.operate.data.ResultCode;
import com.quickask.service.AnswerService;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Logger;

/**
 * Created by NaSa on 2015/10/2.
 */
public class AnswerAction extends ActionSupport {

    private AnswerService answerService;
    private String refreshToken;
    private Map<String, Object> responseResult = new LinkedHashMap<String, Object>();
    private Integer pageNo;
    private Integer pageSize;
    private Integer questionId;
    private Integer answerId;
    private Integer userId;
    private String answerJson;


    public void setAnswerService(AnswerService answerService) {
        this.answerService = answerService;
    }

    //http://localhost:8080/QuickAsk/answer/addAnswer.do
    //answerJson参数 {"userId": 3,"questionId": 2,"answerContent": "不清楚哎？","altitude":0.56,"longitude":108.375445,"latitude":22.716363,"provinceCode":"44","cityCode":"4401","blockCode":"440113","locationDetail": "大学城南五路"}
    public String addAnswer() {
        if (answerJson == null) {
            responseResult.put("data", null);
            responseResult.put("flag", false);
            responseResult.put("code", ResultCode.PARAMS_ERROR);
            responseResult.put("msg", ResultCode.getErrmsg(ResultCode.PARAMS_ERROR));
            return SUCCESS;
        }
        AsknowAnswerSet asknowAnswerSet = answerService.addAnswer(answerJson,refreshToken);
        if (asknowAnswerSet!=null) {
            responseResult.put("data", asknowAnswerSet);
            responseResult.put("flag", true);
            responseResult.put("code", ResultCode.SUCCESS);
            responseResult.put("msg", ResultCode.getErrmsg(ResultCode.SUCCESS));
        } else {
            responseResult.put("data", null);
            responseResult.put("flag", false);
            responseResult.put("code", ResultCode.UNKNOWN_ERROR);
            responseResult.put("msg", ResultCode.getErrmsg(ResultCode.UNKNOWN_ERROR));
        }
        return SUCCESS;
    }


    public Map<String, Object> getResponseResult() {
        return responseResult;
    }

    public void setResponseResult(Map<String, Object> responseResult) {
        this.responseResult = responseResult;
    }


    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getQuestionId() {
        return questionId;
    }

    public void setQuestionId(Integer questionId) {
        this.questionId = questionId;
    }

    public Integer getAnswerId() {
        return answerId;
    }

    public void setAnswerId(Integer answerId) {
        this.answerId = answerId;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getAnswerJson() {
        return answerJson;
    }

    public void setAnswerJson(String answerJson) {
        this.answerJson = answerJson;
    }
}
